import { delay } from 'redux-saga'
import { call, put, takeEvery } from 'redux-saga/effects';
import axios from 'axios';
import { updateData, FETCH_USER } from '@/action/userAction';

function* fetchUser() {
    yield put(updateData({ loading: true }));
    yield delay(1000);
    const res = yield call(axios.get, '/api/userList');

    if (+res.data.code === 0) {
        const { data } = res.data;
        const params = {
            loading: false,
            list: data.list,
            total: data.total,
            current: data.pageIndex,
        }
        yield put(updateData(params));
    }
}

function* userSaga() {
    yield takeEvery(FETCH_USER, fetchUser)
}

export default userSaga;
